{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "自定义ccf函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import scipy.signal as sg\n",
    "\n",
    "def ccf(x, y, lag_max = 100):\n",
    "    result = sg.correlate(y - np.mean(y), x - np.mean(x), method='direct') / (np.std(y) * np.std(x) * len(x))\n",
    "    length = int((len(result) - 1) / 2)\n",
    "    low = length - lag_max\n",
    "    high = length + (lag_max + 1)\n",
    "    return result[low:high]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "绘制互相关图表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA4QAAAELCAYAAACBN0gfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3de5hkZX3g8e9vGJnYXlFGRKC7jYLXVaIjwcQLiZigm0AuJjGprDdibS64YtRItp+4RJ/a9RJXsqur6THZmKQSYkw0qCR4iYNuEgiDAnJTEKcbEGFU1JiOg8hv/6jTUNN0XU51ddXpqu/neerpqlPnfftX1W+/5/zO+55zIjORJEmSJE2fbeMOQJIkSZI0HiaEkiRJkjSlTAglSZIkaUqZEEqSJEnSlDIhlCRJkqQpZUIoSZIkSVNq+7gDaBcRpwC/DxwCvCcz37TOOj8PnA0kcHlm/lK3Og8//PCcn58ffrCSJEmStAVceumlX83Mneu9V5mEMCIOAd4JPBe4CbgkIs7LzKvb1jkW+G3ghzPz9oh4WK965+fn2bt372aFLUmSJEmVFhFLnd6r0pTRE4DrM/OGzLwDOBc4bc06LwfemZm3A2TmbSOOUZIkSZImRpUSwqOAG9te31Qsa3cccFxE/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wHfBD4UEYcCRMT9gQ8D1wJPBX4LeOtYIpUkCdg+7gAkSZoUmfnX7a8j4qXAt2gliP8PqAGHAKdn5r8DV0VEA2iOOlZJksARQkmShiYiHhURfx4RX4yIbwG30trWzharPBa4skgGV1086jglSVrlCKEkScPzYeAm4D8DNwN3AlcDh44zKEmSOnGEUJKkIYiIh9IaAfzvmfnxzLwGeAAHH3y9FnhiRNy3bdkJIwxTkqSDmBBKkjQctwNfBV4eEY+OiGcD76Y1Srjqz4HvAbsj4vERcTLwX4v3cqTRSpKECaEkSUORmXcBvwA8CbgSeCfwO8CBtnX+FfhJ4AnAZ2ldYfTs4u3vjDBcSZIAiEwPSEqSNC4RcRrwAeBhmfnVcccjSZouXlRGkqQRiogXAzcANwJPpHXfwg+ZDEqSxsGEUJKk0ToC+F3gSOArwEeA1401IknS1HLKqCRJkiRNKS8qI0mSJElTyoRQkiRJkqaUCaEkSZIkTSkTQkmSJEmaUiaEkiRJkjSlTAglSZIkaUr9f7amtVL9073zAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 1080x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "airmiles = pd.read_csv(\"http://image.cador.cn/data/airmiles.csv\")\n",
    "lakehuron = pd.read_csv(\"http://image.cador.cn/data/LakeHuron.csv\")\n",
    "lhdata = lakehuron.query(\"1937 <= year <= 1960\")\n",
    "x,y = airmiles.miles,lhdata.level\n",
    "\n",
    "out = ccf(x,y)\n",
    "plt.figure(figsize = (15,4)) \n",
    "for i in range(len(out)):\n",
    "    plt.plot([i,i],[0,out[i]],'k-')\n",
    "    plt.plot(i,out[i],'ko')\n",
    "\n",
    "plt.xlabel(\"lag\",fontsize=14)\n",
    "plt.xticks(range(47),range(-23,24,1))\n",
    "plt.ylabel(\"ccf\",fontsize=14)\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
